//
//  MySQLResult.h
//  LibMySQL
//
//  Created by Marcus Grenängen on 2009-07-20.
//  Copyright 2009 SneWs Soft. All rights reserved.
//
#import <Cocoa/Cocoa.h>

#import "MySQLColumn.h"
#import "MySQLRow.h"

@interface MySQLResult : NSEnumerator
{
@protected
	NSStringEncoding	stringEncoding;
	NSMutableArray		*columns;
	NSMutableDictionary *columnMappings;
	
	MYSQL	  *connection;
	MYSQL_RES *result;
	
@private
	long numRows;
	long numColumns;
}

#pragma mark -
#pragma mark Properties
/*
 * @description: Returns a NSArray containing MySQLColumn* objects.
 */
@property (nonatomic, readonly, retain) NSMutableArray *columns;
@property (nonatomic, readonly, retain) NSMutableDictionary *columnMappings;
@property (nonatomic, readonly, assign) MYSQL *connection;
@property (nonatomic, readonly, assign) MYSQL_RES *result;
@property (nonatomic, readonly, assign) long numRows;
@property (nonatomic, readonly, assign) long numColumns;

/// Data convert helpers
+ (id)convertToObjCValue:(char*)mysqlValue fromMySQLType:(int)t withFlags:(int)flags 
		   usingEncoding:(NSStringEncoding)encoding;

//- (id) init;
- (id)initWithResult:(MYSQL_RES *)theResult andConnection:(MYSQL *)c usingEncoding:(NSStringEncoding)e;

//- (void) dealloc;

#pragma mark -
#pragma mark Public fetch operations
/*
 * @description: Returns the number of rows that this result set contains
 */
- (long)rowCount;

/*
 * @description: Returns the number of columns this result set contains.
 */
- (long)columnCount;

/*
 * @description: Returns the row at the specified index
 */
- (MySQLRow *)rowAtIndex:(NSUInteger)rowIndex;

#pragma mark -
#pragma mark Fast enumeration
- (NSArray *)allObjects;
- (id)nextObject;

@end